home *** CD-ROM | disk | FTP | other *** search
- /************************************************************
- *
- *
- * Unit containing instruction code.
- *
- * by Adrian Bool in cooperation with Graham Cox.
- *
- * copyright © phantasm coding 1992.
- *
- *
- ************************************************************/
-
- #include "Global.h"
- #include "Code.h"
-
- #include "Code.proto.h"
-
- /* memory referance instructions */
-
- void assembleOpcode(opcode opCode,short pass,rBlock theDestination,short *size,pHandle theProgram)
- {
- (pdp8[opCode]).itsFunction(pass,theDestination,size,theProgram);
- }
-
-
- void cmpAND(short pass,rBlock data,short *size,pHandle theProgram)
- { /* ANDs the ACC with amemory location */
- *size=1;
- if (pass == 1)
- {
- str255 dummy;
- *size = 1;
- getSection(theProgram,dummy);
- }
- if (pass == 2)
- {
- makeMemoryInstruction(and,data,theProgram);
- }
- }
-
- void cmpTAD(short pass,rBlock data,short *size,pHandle theProgram)
- { /* adds a memory location to the ACC */
- *size = 1;
- if (pass == 1)
- {
- str255 dummy;
- getSection(theProgram,dummy);
- }
- if (pass == 2)
- {
- makeMemoryInstruction(tad,data,theProgram);
- }
- }
-
- void cmpISZ(short pass,rBlock data,short *size,pHandle theProgram)
- { /* increments memory location then skips if result = 0 */
- *size = 1;
- if (pass == 1)
- {
- str255 dummy;
- getSection(theProgram,dummy);
- }
- if (pass == 2)
- {
- makeMemoryInstruction(isz,data,theProgram);
- }
- }
-
- void cmpDCA(short pass,rBlock data,short *size,pHandle theProgram)
- { /* deposit ACC in memory then set ACC to 0 */
- *size = 1;
- if (pass == 1)
- {
- str255 dummy;
- getSection(theProgram,dummy);
- }
- if (pass == 2)
- {
- makeMemoryInstruction(dca,data,theProgram);
- }
- }
-
- void cmpJMS(short pass,rBlock data,short *size,pHandle theProgram)
- { /* jump to subroutine */
- *size = 1;
- if (pass == 1)
- {
- str255 dummy;
- getSection(theProgram,dummy);
- }
- if (pass == 2)
- {
- makeMemoryInstruction(jms,data,theProgram);
- }
- }
-
- void cmpJMP(short pass,rBlock data,short *size,pHandle theProgram)
- { /* jump to address */
- *size=1;
- if (pass == 1)
- {
- str255 dummy;
- getSection(theProgram,dummy);
- }
- if (pass == 2)
- {
- makeMemoryInstruction(jmp,data,theProgram);
- }
- }
-
- void cmpIO(short pass,rBlock data,short *size,pHandle theProgram)
- { /* input/output instruction */
- *size = 1;
- if (pass == 1)
- {
- str255 dummy;
- getSection(theProgram,dummy);
- }
- if (pass == 2)
- {
- str255 theOperand;
- wordType theAddress;
-
- getSection(theProgram,theOperand);
- theAddress = evaluateValue(theProgram,theOperand);
- data[0] = pdp8[io].iNumber << 9;
- data[0] |= (theAddress & 63) << 3;
- }
- }
-
- /* accumulator instructions : group one */
-
- void cmpCLL(short pass,rBlock data,short *size,pHandle theProgram)
- { /* clear link */
- *size = 1;
- if (pass == 2) data[0] = pdp8[cll].iNumber;
- }
-
- void cmpCMA(short pass,rBlock data,short *size,pHandle theProgram)
- { /* complement accumulator */
- *size = 1;
- if (pass == 2) data[0] = pdp8[cma].iNumber;
- }
-
- void cmpCML(short pass,rBlock data,short *size,pHandle theProgram)
- { /* complement link */
- *size = 1;
- if (pass == 2) data[0] = pdp8[cml].iNumber;
- }
-
- void cmpIAC(short pass,rBlock data,short *size,pHandle theProgram)
- { /* increment accumulator */
- *size = 1;
- if (pass == 2) data[0] = pdp8[iac].iNumber;
- }
-
- void cmpRAR(short pass,rBlock data,short *size,pHandle theProgram)
- { /* rotate accumulator one position right */
- *size = 1;
- if (pass == 2) data[0] = pdp8[rar].iNumber;
- }
-
- void cmpRAL(short pass,rBlock data,short *size,pHandle theProgram)
- { /* rotate accumulator one position left */
- *size = 1;
- if (pass == 2) data[0] = pdp8[ral].iNumber;
- }
-
- void cmpRTR(short pass,rBlock data,short *size,pHandle theProgram)
- { /* rotate accumulator two positions right */
- *size = 1;
- if (pass == 2) data[0] = pdp8[rtr].iNumber;
- }
-
- void cmpRTL(short pass,rBlock data,short *size,pHandle theProgram)
- { /* rotate accumulator two positions left */
- *size = 1;
- if (pass == 2) data[0] = pdp8[rtl].iNumber;
- }
-
- void cmpNOP(short pass,rBlock data,short *size,pHandle theProgram)
- { /* no operation */
- *size = 1;
- if (pass == 2) data[0] = pdp8[nop].iNumber;
- }
-
- /* accumulator instuctions : group 2 */
-
- void cmpSMA(short pass,rBlock data,short *size,pHandle theProgram)
- { /* skip on minus accumulator */
- *size = 1;
- if (pass == 2) data[0] = pdp8[sma].iNumber;
- }
-
- void cmpSZA(short pass,rBlock data,short *size,pHandle theProgram)
- { /* skip on zero link */
- *size = 1;
- if (pass == 2) data[0] = pdp8[sza].iNumber;
- }
-
- void cmpSNL(short pass,rBlock data,short *size,pHandle theProgram)
- { /* skip on non-zero link */
- *size = 1;
- if (pass == 2) data[0] = pdp8[snl].iNumber;
- }
-
- void cmpSPA(short pass,rBlock data,short *size,pHandle theProgram)
- { /* skip on positive accumulator */
- *size = 1;
- if (pass == 2) data[0] = pdp8[spa].iNumber;
- }
-
- void cmpSNA(short pass,rBlock data,short *size,pHandle theProgram)
- { /* skip on non-zero accumulator */
- *size = 1;
- if (pass == 2) data[0] = pdp8[sna].iNumber;
- }
-
- void cmpSZL(short pass,rBlock data,short *size,pHandle theProgram)
- { /* skip on zero link */
- *size = 1;
- if (pass == 2) data[0] = pdp8[szl].iNumber;
- }
-
- void cmpCLA(short pass,rBlock data,short *size,pHandle theProgram)
- { /* clear accumulator */
- *size = 1;
- if (pass == 2) data[0] = pdp8[cla].iNumber;
- }
-
- void cmpOSR(short pass,rBlock data,short *size,pHandle theProgram)
- { /* or switches in accumulator */
- /* not implementated */
- AsmError = OSRNotImplemented;
- }
-
- void cmpHLT(short pass,rBlock data,short *size,pHandle theProgram)
- { /* Halt proccessor */
- *size = 1;
- if (pass == 2) data[0] = pdp8[hlt].iNumber;
- }
-
- /* pseudo operations */
-
- void cmpORG(short pass,rBlock data,short *size,pHandle theProgram)
- { /* set start address of code */
- *size = 0;
- if (pass == 1)
- {
- str255 startAddress;
- addressType theAddress;
-
- getSection(theProgram,startAddress);
- theAddress = evaluateAddress(theProgram, startAddress);
-
- if (!AsmError)
- {
- (*(*theProgram)->objectCode)->startAddress = theAddress;
- (*(*theProgram)->objectCode)->address = theAddress;
- }
- }
- if (pass == 2)
- {
- str255 dummy;
-
- getSection(theProgram,dummy);
- }
- }
-
- void cmpEQU(short pass,rBlock data,short *size,pHandle theProgram)
- { /* equate symbol to value */
- *size = 0;
- if (pass == 1)
- {
- str255 theLabel;
- str255 theValue;
-
- biggestType aValue;
-
- getSection(theProgram,theLabel);
- getSection(theProgram,theValue);
-
- aValue = evaluateValue(theProgram,theValue);
-
- if (!AsmError)
- newLabel(theProgram,theLabel,aValue);
- }
- if (pass == 2)
- {
- str255 dummy;
-
- getSection(theProgram,dummy);
- getSection(theProgram,dummy);
- }
- }
-
- void cmpEND(short pass,rBlock data,short *size,pHandle theProgram)
- { /* signify physical end of source code */
- *size = 0;
- }
-
- void cmpDATA(short pass,rBlock returnData,short *size,pHandle theProgram)
- { /* allocate values to memory locations */
- str255 theData;
- str255 aData;
- short position;
- wordType theValue;
-
- *size = 0;
- position = 0;
- theValue = 0;
-
- getSection(theProgram,theData);
-
- while (getSegment(theData,&position,aData) && (!AsmError))
- {
- if (pass == 2)
- {
- theValue = evaluateValue(theProgram,aData);
- if(!AsmError)
- returnData[*size] = theValue;
- }
- (*size)++;
- }
- }
-
- void cmpSTORE(short pass,rBlock data,short *size,pHandle theProgram)
- { /* allocate a number of words in memory */
- short x,noOfWords;
- str255 request;
-
- getSection(theProgram,request);
- noOfWords = evaluateValue(theProgram,request);
-
- if(!AsmError)
- {
- for(x = 0 ; x < noOfWords ; x++) data[x] = 0;
- *size = noOfWords;
- }
- }
-
-
-
-
-
-
-
-
-
-
-